package com.huqing.icu;

import com.google.common.collect.Lists;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.system.JavaVersion;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.TimeZone;

//@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = "com.huqing.icu")
@MapperScan("com.huqing.icu.**.mapper")
@EnableFeignClients(basePackages = "com.huqing.icu.*")
@EnableDiscoveryClient
public class HouseApplication {

    private static final Logger logger = LoggerFactory.getLogger(HouseApplication.class);

    public static void main(String[] args) {

        //SpringApplication.run(HouseApplication.class, args);

        TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
        SpringApplication springApplication = new SpringApplication();
        //springApplication.addListeners(new ApplicationPreparedEventListener()); // 增加事件监听
        springApplication.addPrimarySources(Lists.newArrayList(HouseApplication.class));
        ConfigurableApplicationContext applicationContext = springApplication.run(args);

        ConfigurableEnvironment environment = applicationContext.getEnvironment();
        //MinioApiSdk bean = applicationContext.getBean(MinioApiSdk.class);
        String ip = null;
        try {
            ip = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            logger.error(e.toString());
        }
        Boolean enableArthas = environment.getProperty("spring.arthas.enabled", Boolean.class, true);
        logger.info("\n-----------------------------------------------------------------\n\t" +
                        "Application '{}' is running! java version: {}\n\t" +
                        "Server  Url:\thttp://{}:{}\n\t" +
                        "Knife4j Doc:\thttp://{}:{}/doc.html\n\t" +
                        "Druid Console:\thttp://{}:{}/druid/index.html\n\t" +
                        (enableArthas ? "Arthas Console:\thttp://{}:{}\n" : "") +
                        "-----------------------------------------------------------------",
                environment.getProperty("spring.application.name"), JavaVersion.getJavaVersion(),
                ip, environment.getProperty("server.port"),
                ip, environment.getProperty("server.port"),
                ip, environment.getProperty("server.port"),
                ip, environment.getProperty("arthas.http-port")
        );
    }
}
